package com.qiuzhiyi.net;

import com.qiuzhiyi.item.BaseItem;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;

/**
 * Author: Li
 * Date: 2017/9/20 0020
 * Description:
 */

public abstract class SelectorObserver<T> implements Observer<T> {

    @Override
    public void onNext(@NonNull T item) {

        BaseItem baseModel = (BaseItem) item;
        if (baseModel.getCode() .equals("200") ) {
            onSuccess(item);
        } else {
            onErrorCodeInfo(baseModel.getCode(), baseModel.getValue());
        }
    }

    @Override
    public void onComplete() {
        onFinish();
    }

    @Override
    public void onError(Throwable e) {
        onFinish();
    }

    protected abstract void onErrorCodeInfo(String code, String info);


    protected abstract void onSuccess(T item);

    protected abstract void onFinish();
}
